#ifndef _MACHINE_STAT_H
#define _MACHINE_STAT_H
//#include <stdint.h>
//#include "r_smc_entry.h"
#include "soft_time.h"
#include "sc95f.h"
//位置不清楚
#define RelayCtr5      (PORT1.PODR.BIT.B5)
#define RelayCtr3      (PORT1.PODR.BIT.B4)
#define RelayCtr4      (PORTH.PODR.BIT.B3)
#define RelayCtr2      (PORT4.PODR.BIT.B2)
#define RelayCtr1      (PORT4.PODR.BIT.B5)
#define RelayCtr6      (PORT4.PODR.BIT.B6)

#define fan_speed_low       RelayCtr4
#define fan_speed_middle    RelayCtr5
#define fan_speed_hight     RelayCtr6//RelayCtr6
#define Floor_heating_valve RelayCtr2 //地暖阀
#define Coil_valve          RelayCtr3
//#define Linkage_switch1     RelayCtr1
#define Linkage_switch      RelayCtr1

#define fan_off            0x10
#define	fan_low            0
#define	fan_middle         1
#define	fan_higth          2
#define	fan_auto           3

#define none                                          0
#define refrigeration                                 1
#define heating                                       2
#define Underfloor_heating                            3
#define heating_and_Underfloor_heating                4
#define ventilate_mode                                5

#define init_all_time           15
#define run_lcd_time            15

#define brightest               0xff
#define half_brightness         0x7f
#define extinguish              0x00

#define TEMP_UPDATE             5

#define ERR_E1          0Xe1

#define ERR_E2          0Xe2

#define ERR_E3          0Xe3

#define ERR_H1          0x01

#define ERR_L0          0x02

#define ERR_CON         0x01

#define ERR_NO_CON      0x02 

#define ERR_MASTER      0xe6

#define TEMP            5

#define TEMP_2          10

#define SETTING_MAX     16

#define min_change         0x02
#define week_change         0x00
#define hour_change         0x01

#define A_KEY_POWER_ON       1
#define A_KEY_POWER_OFF      2

#define POWER_ON             1
#define POWER_OFF            0

typedef enum{

    MODE_INIT,//0
    MODE_POWEROFF,//2
	MODE_LINKAGE_MODBUS_MASTER,
	MODE_LINKAGE_MODBUS_SLAVE,
	MODE_MODBUS_MASTER,
	MODE_MODBUS_SLAVE,
	MODE_HOT_MASTER,
	MODE_HOT_SLAVE,
    MODE_ERR,
	MODE_PARAMETER_SETTING,
	MODE_VERSION,
	MODE_TEMP_CHANGED,
	MODE_TIME_CHANGED,
	MODE_TEST = 0XFF,

}Machine_Stat ;

//typedef struct
//{
//	//1开机,,0关机
//	uint8_t power_data;
//	uint8_t self_mode;
//	uint8_t fan_speed;
//	uint8_t fan_disc_valve;
//	uint8_t floor_heating_valve;
//	uint8_t ganged_switch;
//
//	uint16_t setting_temperature;
//	uint16_t current_temperature;
//	uint8_t error_code;
//	uint8_t error_mode;
//	uint8_t child_lock;
//	uint8_t a_key_power;//1是kai，0是wu 2是guan
//	uint16_t maximun_temperature;
//	uint16_t minmun_temperature;
//
//}slave_04_data.main_data;
//typedef struct
//{
//	uint8_t slave_addr1;
//	uint8_t function_code;
//	uint8_t length_data;
//	uint16_t reservation;
//	uint16_t change_flag;//0为关机，1为模式。
//	slave_04_data.main_data slave_04_data.main_data;
//	uint8_t receive_slave_poweron;
//	uint8_t receive_slave_mode;
//	uint8_t receive_slave_temp;
//	uint8_t receive_data;
//	uint8_t quick_heat;
//	uint8_t master_mode;
//	uint8_t master_repeat;
//	uint8_t salver_repeat;
//	uint8_t Braking_demand;
//}rinnai_data;

typedef struct
{
	uint16_t self_mode;
	uint16_t fan_speed;
	uint16_t setting_temperature;
	uint16_t current_temperature;
	uint16_t maximun_temperature;
	uint16_t minmun_temperature;
	uint16_t slave_err_E1 :1;
	uint16_t slave_err_E2 :1;
	uint16_t slave_err_H1 :1;
	uint16_t slave_err_LO :1;
	uint16_t reserved0 :12;
	uint16_t prevent_frostbite_power :1;
	uint16_t power_data :1;
	uint16_t a_key_power :2;
	uint16_t child_function :1;
	uint16_t ganged_switch :1;
	uint16_t fan_disc_valve :1;
	uint16_t floor_heating_valve :1;
	uint16_t waiji_power_on :1;
	uint16_t reserved1 :7;
}MAIN_DATA;
typedef union
{
	MAIN_DATA main_data;
	uint8_t data_04[16];
}SLAVE_04_DATA;
typedef struct
{
	SLAVE_04_DATA slave_04_data;
	uint16_t reservation;//预约
	uint16_t change_flag;//0为关机，1为模式。
	//slave_04_data.main_data slave_04_data.main_data;
	uint8_t receive_slave_poweron;
	uint8_t receive_slave_mode;
	uint8_t receive_slave_temp;
	uint8_t receive_data;
	uint8_t quick_heat;
	uint8_t master_mode;
	uint8_t master_repeat;
	uint8_t salver_repeat;
	uint8_t Braking_demand;
	uint8_t error_code;
	uint8_t error_mode;
}RINNAI_DATA;
typedef union{
	uint8_t set[SETTING_MAX];
	//uint8_t timer_mode;
	struct
	{
	uint8_t addr;//0  1
	uint8_t childlock_open;
	uint8_t run_mode;

	//uint8_t water_time;
	uint8_t valve_fan_control;//3   4
	uint8_t led_power;
	uint8_t prevent_frostbite;

	uint8_t factory_data_reset;//6   7
	uint8_t display_temperature;
	uint8_t cool_hearing_temperature;

	//uint8_t hearing_furnace_open;
	uint8_t buzzer_open;//9   10
	uint8_t power_led_set;
	uint8_t cainuanlu_time_open;

	uint8_t cainuanlu_in_temp;//12    13
	uint8_t return_water_time;
	uint8_t cainuanlu_quit_temp;

	uint8_t link_close_time;//15    16
	}data1;

}SETTING_DATA;

typedef struct
{
	uint16_t wander_link:1;
	uint16_t wander_power1:1;
	uint16_t broadcast_a_key_power:2;
	uint16_t broadcast_wander_err:1;
	uint16_t broadcast_ganged_switch:1;
	uint16_t reserved2 :10;
	uint16_t broadcast_mode;
}BROADCAST_MAIN;
typedef union
{
	BROADCAST_MAIN broadcast_main;
	uint8_t broadcast_main_data[4];
}BROADCAST_MAIN_DATA;
typedef struct
{

	uint8_t wander_mode;
	uint16_t cool_temp;
	uint16_t heat_temp;
	uint8_t wander_power:1;
	uint8_t wander_err:1;
	uint8_t wander_ele_heat:1;
	uint8_t wander_prevent_frostbite:1;
	uint8_t wander_chushuang:1;
	uint8_t reserved3:3;
	uint16_t wander_out_water;
	uint16_t wander_in_water;
	uint16_t envir_temp;
	uint16_t yasuoji_fre;
	//0为一键关机变动，
}WANDER_LEAD_CONTROLLER;


extern uint8_t link_flag;
extern Time wifitime;
extern Time timeout;
extern Time flash_time;
extern SETTING_DATA setting_data;
extern RINNAI_DATA rinnai_data;
extern BROADCAST_MAIN_DATA broadcast_main_data;
extern WANDER_LEAD_CONTROLLER wander_lead_controller;
extern uint8_t parameter_setting;
extern uint8_t setting_flag;
void machine_stat(void);
extern Machine_Stat MachineStat;
extern uint8_t time_change;
extern uint8_t comm_times;
//extern RESERVATION_TIME reservation_time;
uint16_t mode_changed(void);
uint16_t fan_key(uint16_t fan);
void valve_and_fan(void);
//void key_process(void);
void soft_init(void);
void wifi_init(void);
uint8_t lcd_brightness(uint8_t lcd_light1);
void linkage_Linkage_switch(void);
void reservation_function(void);
#endif
